// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#ifndef SPI_FILTER_IRQ_HANDLER_H_
#define SPI_FILTER_IRQ_HANDLER_H_

#include "status/rot_status.h"
#include "host_fw/host_state_manager.h"


/**
 * Handler instance for processing interrupts for the SPI filter of a single host.
 */
struct spi_filter_irq_handler {
	/**
	 * Handle the interrupt indicating that a read-only flash region has been written to.
	 *
	 * @param handler The handler context.
	 */
	void (*ro_flash_dirty) (struct spi_filter_irq_handler *handler);

	struct host_state_manager *host_state;		/**< State of the host for the SPI filter. */
};


int spi_filter_irq_handler_init (struct spi_filter_irq_handler *handler,
	struct host_state_manager *host_state);
void spi_filter_irq_handler_release (struct spi_filter_irq_handler *handler);

/* Internal functions for use by derived types. */
void spi_filter_irq_handler_ro_flash_dirty (struct spi_filter_irq_handler *handler);


#define	SPI_FILTER_IRQ_ERROR(code)		ROT_ERROR (ROT_MODULE_SPI_FILTER_IRQ, code)

/**
 * Error codes that can be generated by a filter IRQ handler.
 */
enum {
	SPI_FILTER_IRQ_INVALID_ARGUMENT = SPI_FILTER_IRQ_ERROR (0x00),	/**< Input parameter is null or not valid. */
	SPI_FILTER_IRQ_NO_MEMORY = SPI_FILTER_IRQ_ERROR (0x01),			/**< Memory allocation failed. */
	SPI_FILTER_IRQ_STATUS_FAIL = SPI_FILTER_IRQ_ERROR (0x02),		/**< Error determining IRQ status. */
};


#endif /* SPI_FILTER_IRQ_HANDLER_H_ */
